
public class AverageVisitor implements Visitor {

	private float average = 0;
	private float sum = 0;
	private float noEmployees = 0;
	
	@Override
	public void visit(Employee e) {
		sum += e.getSalary();
		noEmployees += 1;
	}
	
	@Override
	public void visit(Boss b) {
		sum += b.getSalary();
		noEmployees += 1;
		
		for (Employee e : b.getSubordinates())
			e.accept(this);
	}
	
	public float getAverage() {
		average = sum / noEmployees;
		return average;
	}
}
